import {h} from "vue";
import {NButton} from "naive-ui";
/*
*   表格字段相关的
*/
export const useColumns = (handleView: Function|null=null, handleEdit: null| Function=null, handleDelete: null|Function=null) => {
    const index = {
        title: "序号", key: "index", width: 60, align: "center", show: true, render: (rowData: any, rowIndex: number) => {
            return rowIndex + 1
        }
    }
    const createdTime = {
        title: "创建时间", key: "createdTime", show: true,width:150, render: (rowData: any,) => {
            // @ts-ignore
            return new Date().toMyString(rowData["createdTime"])
        }
    }
    const changeTime = {
        title: "更新时间", key: "changeTime", show: true,width:150, render: (rowData: any,) => {
            // @ts-ignore
            return new Date().toMyString(rowData["changeTime"])
        }
    }
    const desc = {title: "描述", key: "desc", show: true,width:100,}
    const view = {
        title: "查看", key: "view", width: 80, align: "center", show: true, render: (rowData: any,) => {
            return h(NButton, {
                onClick: () => {
                    handleView && handleView(rowData)
                }, size: "small",type:"success",
            }, {
                default() {
                    return "查看"
                }
            })
        }
    }
    const edit = {
        title: "编辑", key: "view", width: 80, align: "center", show: true, render: (rowData: any,) => {
            return h(NButton, {
                onClick: () => {
                    handleEdit && handleEdit(rowData)
                }, size: "small",type:"info",
            }, {
                default() {
                    return "编辑"
                }
            })
        }
    }
    const del = {
        title: "删除", key: "view", width: 80, align: "center", show: true, render: (rowData: any,) => {
            return h(NButton, {
                onClick: () => {
                    handleDelete && handleDelete(rowData)
                }, size: "small",type:"error",
            }, {
                default() {
                    return "删除"
                }
            })
        }
    }
    return {index, createdTime, changeTime,desc, view, edit, del}
}
